﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Program15_GDI
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            //把图片读入内存
            MemoryStream ms = new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePicture(ValidateCode.CreateVCode(4)), 0, ValidateCode.CreateVCodePicture(ValidateCode.CreateVCode(4)).Length);
            //显示图片的文件流格式
            pb_vCode.Image = Image.FromStream(ms);
        }
        /// <summary>
        /// 绘直线
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnLine_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //创建画笔对象
            Pen pen=new Pen(Brushes.BlueViolet,5.0F);
            //线条风格
            //pen.DashStyle = DashStyle.DashDot;
            float[] dasValues = {5, 2, 11, 4};
            pen.DashPattern = dasValues;

            //画直线，建立坐标
            Point p1=new Point(30,50);
            Point p2=new Point(300,500);

            //绘制直线
            g.DrawLine(pen,p1,p2);
            
        }

        private void btnRect_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            Pen pen=new Pen(Brushes.Coral,5.0F);

            //定义矩形大小
            Size size=new Size(100,80);
             Point p1=new Point(60,50);
             Rectangle rectangle=new Rectangle(p1,size);

             g.DrawRectangle(pen,rectangle);
        }

        private void btnClicle_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            Pen pen = new Pen(Brushes.DeepPink,5.0F);
            g.DrawEllipse(pen,100,100,200,200);
        }

        private void btnPie_Click(object sender, EventArgs e)
        {
            //创建GDI对象
            Graphics g = this.CreateGraphics();
            //Pen pen = new Pen(Brushes.Chartreuse, 5.0F);
            //g.DrawPie(pen,50,100,200,200,45,45);
            //pen = new Pen(Brushes.BlueViolet, 5.0F);
            //g.DrawPie(pen,50,100,200,200,135,45);
            SolidBrush bush=new SolidBrush(Color.BlueViolet);
            g.FillPie(bush,50,100,200,200,45,90);
            Color mycolor = Color.FromArgb(1, 1, 1);
            bush = new SolidBrush(mycolor);
            g.FillPie(bush, 50, 100, 200, 200, 135, 45);
            bush = new SolidBrush(Color.DarkOrange);
            g.FillPie(bush, 50, 100, 200, 200, 180, 35);
            bush = new SolidBrush(Color.DeepPink);
            g.FillPie(bush, 50, 100, 200, 200, 360, 90);
            bush = new SolidBrush(Color.MediumSpringGreen);
            g.FillPie(bush, 50, 100, 200, 200, 200, 45);
            bush = new SolidBrush(Color.DarkSlateBlue);
            g.FillPie(bush, 50, 100, 200, 200, 240, 60);
            bush = new SolidBrush(Color.CornflowerBlue);
            g.FillPie(bush, 50, 100, 200, 200, 300, 60);

            //写字
            g.DrawString("年度业绩",new Font("微软雅黑",14,FontStyle.Bold),Brushes.DarkOrange,new PointF(20,300) );
        }

        private int i = 0;
        /// <summary>
        /// 当窗体绘图时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Paint(object sender, PaintEventArgs e)
        {
            i++;
            lblCount.Text = i.ToString();
        }

        private void label1_Click(object sender, EventArgs e)
        {
            //label1.Text = ValidateCode.CreateVCode(4);
            //把图片读入内存
            MemoryStream ms=new MemoryStream();
            ms.Write(ValidateCode.CreateVCodePicture(ValidateCode.CreateVCode(4)),0,ValidateCode.CreateVCodePicture(ValidateCode.CreateVCode(4)).Length);
           //显示图片的文件流格式
            pb_vCode.Image=Image.FromStream(ms);
        }
    }
}
